package cn.xaut.XAUT迎春杯预热;

import static java.lang.Math.*;
import java.util.Scanner;

/**
 * F - 最短区间
 */
public class demoF {

    public static void main(String[] args) {
        
        Scanner input = new Scanner(System.in);
        int s = input.nextInt();
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) 
            a[i] = input.nextInt();

        int res = n + 1;
        for (int i = 0; i < n; i++) {
            int sum = 0, count = 0;
            for (int j = i; j < n; j++) {
                if (sum >= s || count >= res)   // 剪枝
                    break;
                sum += a[j];
                count ++;
            }
            if (sum >= s)   // 防止最后几个数误导结果
                res = min(res, count);
        }
        System.out.println(res == n + 1 ? 0 : res);
    }
}
